package com.example.chat04.service;

import com.example.chat04.model.ChatMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Service
public class ChatService {

    @Autowired
    SimpMessagingTemplate simpMessagingTemplate;

    public void sendMsgToAll(ChatMessage chatMessage){
        Assert.notNull(chatMessage,"The class must not be null");
        simpMessagingTemplate.convertAndSend("/topic/chat.public",chatMessage);
    }

}
